package com.digitalart.nav {
	import com.digitalart.commons.TextFormatter;      
	
	import flash.text.TextFieldAutoSize;
	import flash.text.TextField;
	import flash.display.Bitmap;
	
	import flash.display.Sprite;
	
	/**
	 * @author johan.chaves
	 */
	public class NavView extends Sprite {                           
		
		private static const LOGO_POS_X : Number = 23;
		private static const LOGO_POS_Y : Number = 8;
		private static const TEXT_LOGO_POS_X : Number = 23;
		private static const TEXT_LOGO_POS_Y : Number = 4;
		
		private var _homeLogoContainer : Sprite;
		private var _backgroundImage : Bitmap;
		private var _logoImage : Bitmap;
		private var _textFieldContainer : Sprite;
		
		
		
		/**********************************Constructor*************************/
		
		public function NavView() {             
			
			homeLogoContainer = new Sprite();       
			textFieldContainer = new Sprite();                                                              
		}
		
		
		/**********************************************************************/
		
		/**********************************Methods*************************/
		
		private function setbackGroundColor() : void {
			
			var backSpriteColor : Sprite = new Sprite();
			backSpriteColor.graphics.beginFill(0x000000);
			backSpriteColor.graphics.drawRect(0, 0, 750, 45);
			backSpriteColor.graphics.endFill();
			backSpriteColor.alpha = 0.5;
			this.addChild(backSpriteColor);
		}
		
		public function addImages():void{
			
			this.addChild(backgroundImage);
			setbackGroundColor();
			this.addChild(homeLogoContainer);
			homeLogoContainer.addChild(logoImage);
		}
		
		public function addLogoContainerText(text : String):void{
			
			var textField : TextField = new TextField();
			textField.htmlText = text;
			TextFormatter.setTextFormat(textField);         
			
			textFieldContainer.addChild(textField);
			textFieldContainer.x += TEXT_LOGO_POS_X;
			textFieldContainer.y += TEXT_LOGO_POS_Y;
			homeLogoContainer.addChild(textFieldContainer);
			locateHomeLogoContainer();
			setHomeLogoHitTest();
		}
		
		private function setHomeLogoHitTest() : void {
			
			var hitTest : Sprite = new Sprite();
			hitTest.graphics.beginFill(0x000000);
			hitTest.graphics.drawRect(homeLogoContainer.x, homeLogoContainer.y, homeLogoContainer.width, homeLogoContainer.height);
			hitTest.graphics.endFill();
			hitTest.alpha = 0;
			hitTest.buttonMode = true;
			homeLogoContainer.addChild(hitTest);                    
		}
		
		private function locateHomeLogoContainer() : void {
			
			homeLogoContainer.x = LOGO_POS_X;
			homeLogoContainer.y = LOGO_POS_Y;
			
			textFieldContainer.x + TEXT_LOGO_POS_X;
			textFieldContainer.y + TEXT_LOGO_POS_Y;                 
		}
		
		
		/**********************************************************************/
		/**************************Getters & Setters***************************/
		
		public function get homeLogoContainer() : Sprite {
			return _homeLogoContainer;
		}
		
		public function set homeLogoContainer(homeLogoContainer : Sprite) : void {
			_homeLogoContainer = homeLogoContainer;
		}
		
		public function get backgroundImage() : Bitmap {
			return _backgroundImage;
		}
		
		public function set backgroundImage(backgroundImage : Bitmap) : void {
			_backgroundImage = backgroundImage;
		}
		
		public function get logoImage() : Bitmap {
			return _logoImage;
		}
		
		public function set logoImage(logoImage : Bitmap) : void {
			_logoImage = logoImage;
		}
		
		public function get textFieldContainer() : Sprite {
			return _textFieldContainer;
		}
		
		public function set textFieldContainer(textFieldContainer : Sprite) : void {
			_textFieldContainer = textFieldContainer;
		}
	}
}